package com.jia.lidao.ui.message;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jia.lidao.R;
import com.jia.lidao.UserUtils;
import com.jia.lidao.enity.MessagetBeen;
import com.jia.lidao.network.http.BusinessManager;
import com.jia.lidao.network.http.MyCallback;
import com.jia.lidao.network.http.request.impl.SetMessageReadRequest;
import com.jia.lidao.widget.CommonTitleBar;

/**
 * Created by 00029935 on 2017/11/18.
 */

public class SystemInforFragment extends BaseFragment {
	private TextView tvTitleM;
	private TextView tvTime;
	private TextView tvContent;
	private ImageView ivGoodPic;
	private MessagetBeen.MessagesBean.DataBean data;

	@Override
	public void onCreate(@Nullable Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		data = (MessagetBeen.MessagesBean.DataBean) getActivity().getIntent()
				.getSerializableExtra("object");

		BusinessManager.getInstance().setMessageRead(new SetMessageReadRequest(data.getMessage_id()), new MyCallback<Void>() {
			@Override
			public void onSuccess(Void result, String message) {
				MessageNoticeListFragment.needrefresh=true;
			}

			@Override
			public void onError(String errorCode, String message) {

			}

			@Override
			public void onFinished() {

			}

			@Override
			public void onRefreshToken() {
				UserUtils.getInstance().goToLogin(getActivity());
			}
		});
	}

	@Override
	protected int getInflateLayout() {
		return R.layout.system_infor_fragment;
	}

	@Override
	protected void setUpView(View view) {
		tvTitleM = (TextView) view.findViewById(R.id.tv_title_m);
		tvTime = (TextView) view.findViewById(R.id.tv_time);
		tvContent = (TextView) view.findViewById(R.id.tv_content);
		ivGoodPic = (ImageView) view.findViewById(R.id.iv_good_pic);

		CommonTitleBar commonTitleBar = (CommonTitleBar) view
				.findViewById(R.id.common_title_bar);
		commonTitleBar.setTitle("详情");

		tvTitleM.setText(data.getTitle());
		tvTime.setText("发布时间  " + data.getCreated_time());
		Glide.with(getContext()).load(data.getPic()).into(ivGoodPic);
		tvContent.setText(data.getContent());
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootView = super.onCreateView(inflater, container,
				savedInstanceState);
		return rootView;
	}
}
